﻿#pragma once

#include <QObject>
#include <QSqlTableModel>
#include <QSqlRecord>
#include "CommonDefine.h"

/**
 * @brief 用来存放客户端信息的SqlModel
*/
class ClientDataRecordSqlTableModel : public QSqlTableModel
{
    Q_OBJECT
    //一共有多少条数据
    Q_PROPERTY(int count READ get_count WRITE set_count NOTIFY count_Notify)
    NORMAL_DATA(count, int, 0)
public:
    enum  ClientDataEnum {
        //账号
        AccountNumber = Qt::UserRole,
        //密码
        Password,
        //状态
        UserState,
        //失败次数
        ErrorTimes,
        //注册日期
        RegistrationDate
    };
    Q_ENUMS(ClientDataEnum)

public:
    ClientDataRecordSqlTableModel();
    QHash<int, QByteArray>  roleNames() const override;
    QVariant                data(const QModelIndex &index, int role) const override;
    void                    insertAccount(const QString& account, const QString& password);
    //查看账号是否存在于model中
    bool                    accountIsInModel(const QString& count, int& index);

public slots:
    void                    removeARow(int row);
    QVariant                getData(int row, int role);
    void                    modifyData(int row, int role, QString tex);

private:
    void                    createTable();
    void                    initStatus();

};

